package com.lyh.hkcloud.util.base;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * 保存及获取设置信息
 */
public class SaveData {

    private static SharedPreferences mShare = null;

    private static SharedPreferences getShared(Context context) {
        if (mShare == null) {
            mShare = context.getSharedPreferences("APP_NAME", Context.MODE_PRIVATE);
        }
        return mShare;
    }

    public static String getString(Context context, String key) {
        return getShared(context).getString(key, "");
    }

    public static Integer getInteger(Context context, String key, int defaultValue) {
        return getShared(context).getInt(key, defaultValue);
    }

    public static boolean getValue(Context context, String key, boolean defaultValue) {
        return getShared(context).getBoolean(key, defaultValue);
    }

    public static void putValue(Context context, String key, String val) {
        Editor editor = getShared(context).edit();
        editor.putString(key, val);
        editor.apply();
    }


    public static void putValue(Context context, String key, int val) {
        Editor editor = getShared(context).edit();
        editor.putInt(key, val);
        editor.apply();
    }

    public static void putValue(Context context, String key, boolean val) {
        Editor editor = getShared(context).edit();
        editor.putBoolean(key, val);
        editor.apply();
    }

}
 
